home *** CD-ROM | disk | FTP | other *** search
- /* Copyright 1983 by the Massachusetts Institute of Technology */
-
- /*
- Copyright Cornell University 1986. All rights are reserved.
-
- As of 4/10/86:
- This source file may have no changes from the M.I.T original
- other than this notice; but it has been tested as part of
- Cornell's Aztec-C port. See notice.h
-
- */
-
- /* 8-13-86 John Lynn remove an extra increament of q_len in the macro q_addh */
- /* 10/24/86 kevin changed 0 to NULL in pointer comparisons */
-
- /* Definitions for general-purpose queue manipulation package.
- Modified from Larry Allen's queue package from CSR Unix for TCP and
- tasks. */
-
- #ifndef _QDEF
-
- #define _QDEF
-
- typedef struct q_elt /* queue element: cast to right type */
- {
- struct q_elt *qe_next; /* it's just a pointer to next elt */
- } *q_elt;
-
- typedef struct queue { /* queue header */
- q_elt q_head; /* first element in queue */
- q_elt q_tail; /* last element in queue */
- int q_len; /* number of elements in queue */
- int q_max; /* maximum length */
- int q_min; /* minimum length */
- } queue;
-
- extern q_elt q_deq ();
- extern queue *q_create();
-
- /* The following macros implement most of the common queue operations */
-
- /* Add an element to the head of the queue */
-
- #define q_addh(q, elt) { \
- if ((q)->q_head == NULL) (q)->q_tail = (elt); \
- (elt)->qe_next = (q)->q_head; \
- (q)->q_head = (elt); \
- if(++((q)->q_len) > (q)->q_max) (q)->q_max = (q)->q_len; \
- }
-
- /* Add an element to the tail of a queue */
-
- #define q_addt(q, elt) { \
- (elt)->qe_next = NULL; \
- if ((q)->q_head == NULL) { \
- (q)->q_head = (elt); \
- } else { \
- (q)->q_tail->qe_next = (elt); \
- } \
- (q)->q_tail = (elt); \
- if(++((q)->q_len) > (q)->q_max) (q)->q_max = (q)->q_len; \
- }
-
- /* Add an element after a specified element in the queue. If prev == */
- /* &q->q_head, can be used to add an element to the head of the queue */
-
- #define q_adda(q, prev, new) { \
- if ((q)->q_tail == (prev) || (q)->q_tail == NULL) { \
- (q)->q_tail = (new); \
- } \
- (new)->qe_next = (prev)->qe_next; \
- (prev)->qe_next = (new); \
- if(++((q)->q_len) > (q)->q_max) (q)->q_max = (q)->q_len; \
- }
-
- #ifdef OLDJUNK
- /* Add an element before a specified element in the queue. */
- /* if head is NULL or succ, just patch new elt right in
- if not, run down list to find previous elt and patch in
- requires q_elt tmpelt to be defined
- */
-
- #define q_addb(q, succ, new) { \
- if ((q)->q_head == NULL || (q)->q_head == (succ) ) { \
- (new)->qe_next = (q)->q_head; \
- if ((q)->q_head == NULL) \
- (q)->q_tail = (new); \
- (q)->q_head = (new); \
- } \
- else { \
- (new)->qe_next = (succ); \
- tmpelt = (q)->q_head; \
- while (tmpelt->qe_next != (succ)) { \
- tmpelt = tmpelt->qe_next; \
- } \
- tmpelt->qe_next = (new); \
- } \
- if(++((q)->q_len) > (q)->q_max) (q)->q_max = (q)->q_len; \
- }
-
- #endif
-
- /* Delete an element from a queue, given a pointer to the preceeding element */
- /* Will delete the first element if prev == &q->q_head */
-
- #define q_dela(q, elt, prev) { \
- if ((q)->q_tail == (elt)) { \
- if ((q)->q_head == (elt)) \
- (q)->q_tail = NULL; \
- else \
- (q)->q_tail = (prev); \
- } \
- (prev)->qe_next = (elt)->qe_next; \
- (elt)->qe_next = NULL; \
- if(--((q)->q_len) < (q)->q_min) (q)->q_min = (q)->q_len; \
- }
-
-
- #define aq_addt(q, elt) {int_off(); q_addt((q), (elt)); int_on(); }
- #define aq_addh(q, elt) {int_off(); q_addh((q), (elt)); int_on(); }
- #define aq_addb(q, oelt, nelt) {int_off(); q_addb((q), (oelt), (nelt)); int_on(); }
-
- extern q_elt aq_deq();
-
- #endif
-